from django.db import models

from utils.model import BaseModel


class CourseCategory(BaseModel):
    """分类"""
    name = models.CharField(max_length=64, unique=True, verbose_name="分类名称")

    class Meta:
        db_table = "swim_course_category"
        verbose_name = "分类"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s" % self.name


class Course(BaseModel):
    """课程"""
    name = models.CharField(max_length=128, verbose_name="课程名称")
    course_img = models.ImageField(upload_to="courses", max_length=255, verbose_name="图片", blank=True, null=True)
    course_img2 = models.ImageField(upload_to="courses", max_length=255, verbose_name="封面图片", blank=True, null=True)
    brief = models.TextField(max_length=2048, verbose_name="详情介绍", null=True, blank=True)
    period = models.IntegerField(verbose_name="建议学习周期(day)", default=120)
    students = models.IntegerField(verbose_name="学习人数", default=0)
    sections = models.IntegerField(verbose_name="总课时数量", default=0)
    price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name="课程价格", default=0)
    teacher = models.ForeignKey("Teacher", on_delete=models.DO_NOTHING, null=True, blank=True, verbose_name="授课老师")
    course_category = models.ForeignKey("CourseCategory", on_delete=models.SET_NULL, db_constraint=False, null=True,
                                        blank=True, verbose_name="课程分类")

    class Meta:
        db_table = "swim_course"
        verbose_name = "课程"
        verbose_name_plural = "课程"

    def __str__(self):
        return "%s" % self.name


class Teacher(BaseModel):
    """导师"""

    name = models.CharField(max_length=32, verbose_name="老师名")
    title = models.CharField(max_length=64, verbose_name="职位、职称")
    image = models.ImageField(upload_to="teacher", null=True, verbose_name="导师封面")
    image2=models.ImageField(upload_to="teacher", null=True, verbose_name="导师照片")
    brief = models.TextField(max_length=1024, verbose_name="导师描述")
    state = models.BooleanField(default=True, verbose_name='是否在岗')

    class Meta:
        db_table = "swim_teacher"
        verbose_name = "导师"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s" % self.name


class Comment(models.Model):
    teacher = models.ForeignKey(to='Teacher', on_delete=models.CASCADE)
    content = models.CharField(max_length=256, verbose_name='评论内容')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='添加时间')

    class Meta:
        db_table = "swim_teacher_commient"
        verbose_name = "评价"
        verbose_name_plural = verbose_name
    def __str__(self):
        return "关于%s的评论" % self.teacher.name